package com.bwsoft.admin.action;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import net.sf.json.JSONObject;

import com.bwsoft.admin.domain.Account;
import com.bwsoft.admin.domain.valueObject.AccountVO;

public class IndividualAndInspectorAction extends BaseAction_ybd{

	/**
	 * 
	 */
	private static final long serialVersionUID = -1147962578997054717L;

	String s_accountId;
	String s_nickName;
	String s_account;
	String s_phone;
	String s_jinyongFlag;
	String s_accountType;

	public String individualAndInspectorIndex(){
		return "individualAndInspectorIndex";
	}

	/**
	 * 查询获取列表
	 */
	public String getDataJson() {

		List<Account> iAndISet=null;
		
			
			//通过字典编号查询字典详情的分页集合
		iAndISet = iAndIService.findData(page, rows, s_accountId,  s_nickName,  s_account,  s_phone,  s_jinyongFlag,  s_accountType);
			//通过编号查询字典集合的大小	
		Long count = iAndIService.getTotalCount(s_accountId,  s_nickName,  s_account,  s_phone,  s_jinyongFlag,  s_accountType);
		List<AccountVO> listVo = iAndIService.getVo(iAndISet);
		responseJson.put("total", count);
		responseJson.put("rows", listVo);

		return "mapJsonResult";
	}
	
	/**
	 * 保存或新增
	 * @return
	 */
	public String saveOrUpdateInfo(){
//		if(cl.getAccountId() == null || "".equals(cl.getAccountId())){
//			if(clImg1 == null || "".equals(clImg1)){
//				responseJson.put("result", "Fail");
//				responseJson.put("message", "请上传认证图！");
//				return "mapJsonResult";
//			}
//			if(clImg1 != null && !"".equals(clImg1) && !newsService.isImage(clImg1ContentType)){
//				responseJson.put("result", "Fail");
//				responseJson.put("message", "上传的文件不是图片类型！");
//				return "mapJsonResult";
//			}
//			if(clImg1 != null && !"".equals(clImg1) && !newsService.isFitSize(clImg1)){
//				responseJson.put("result", "Fail");
//				responseJson.put("message", "图片不能超过8M！");
//				return "mapJsonResult";
//			}
//		}
		msg = iAndIService.saveOrUpdateInfo(il, ilImg1, ilImg1FileName);
		
//		responseJson.put("result", msg.getMsgFlag() ? "Success" : "Fail");
//		responseJson.put("message", msg.getMsgStr());
//		return "mapJsonResult";
		response.setContentType("text/html;charset=utf-8");
		JSONObject json = new JSONObject();
		json.put("result", msg.getMsgFlag() ? "Success" : "Fail");
		json.put("message", msg.getMsgStr());
		try {
			PrintWriter out = response.getWriter();
			out.write(json.toString());
			out.flush();
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return null;
	}
	
	/**
	 * 保存或新增
	 * @return
	 */
	public String saveOrUpdatePass(){
		msg = comAndLadService.saveOrUpdatePass(il);
		
		responseJson.put("result", msg.getMsgFlag() ? "Success" : "Fail");
		responseJson.put("message", msg.getMsgStr());
		return "mapJsonResult";
	}
	
	/**
	 * 获取详情内容
	 * @return
	 */
	public String iAndIModifyInfo(){
		il = comAndLadService.comAndLadModifyInfo(il.getAccountId());
		
		List<Account> list = new ArrayList<Account>();
		list.add(il);
		List<AccountVO> listVo = iAndIService.getVo(list);
		
		responseJson.put("il", listVo.get(0));
		return "mapJsonResult";
	}
	
	public String operation() {
		msg = comAndLadService.operation(il.getAccountId());
		
		responseJson.put("result", msg.getMsgFlag() ? "Success" : "Fail");
		responseJson.put("message", msg.getMsgStr());
		return "mapJsonResult";
	}

	public String forbid() {
		msg = comAndLadService.forbid(il.getAccountId());
		
		responseJson.put("result", msg.getMsgFlag() ? "Success" : "Fail");
		responseJson.put("message", msg.getMsgStr());
		return "mapJsonResult";
	}
//-----------------------------------------------------------------------------------
	public String getS_accountId() {
		return s_accountId;
	}

	public void setS_accountId(String s_accountId) {
		this.s_accountId = s_accountId;
	}

	public String getS_nickName() {
		return s_nickName;
	}

	public void setS_nickName(String s_nickName) {
		this.s_nickName = s_nickName;
	}

	public String getS_account() {
		return s_account;
	}

	public void setS_account(String s_account) {
		this.s_account = s_account;
	}

	public String getS_phone() {
		return s_phone;
	}

	public void setS_phone(String s_phone) {
		this.s_phone = s_phone;
	}

	public String getS_jinyongFlag() {
		return s_jinyongFlag;
	}

	public void setS_jinyongFlag(String s_jinyongFlag) {
		this.s_jinyongFlag = s_jinyongFlag;
	}

	public String getS_accountType() {
		return s_accountType;
	}

	public void setS_accountType(String s_accountType) {
		this.s_accountType = s_accountType;
	}

}